package action.chap6;

import action.chap4.Dish;
import action.chap4.DishUtils;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static java.util.stream.Collectors.*;

public class Demo641 {
    public static void main(String[] args) {
        List<Dish> dishes =
                DishUtils.getListDish();
        Map<Boolean, Map<Dish.Type, List<Dish>>> collect = dishes
                .stream()
                .collect(partitioningBy(Dish::isVegetarian, groupingBy(Dish::getType)));
        //partitioningBy 第一个参数是一个谓语 第二个参数是一个收集器
        //collectingAndThen 第一个参数需要一个收集器  第二个参数需要的是一个Function接口
        Map<Boolean, Dish> collect1 = dishes
                .stream().collect(
                        partitioningBy(Dish::isVegetarian,
                                collectingAndThen(
                                        maxBy(Comparator.comparingInt(Dish::getCalories)),
                                        Optional::get)));
        System.out.println(collect1);
    }
}
